# -*- coding: utf-8 -*-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# 作者：cacho_37967865
# 博客：https://blog.csdn.net/sinat_37967865
# 文件：http_client.py
# 日期：2019-08-29
# 备注：http客户端请求
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import requests
import json


url_comm = 'http://www.example'

#用Requests模拟post请求(application/x-www-form-urlencoded  默认格式)
data = {'parameter1':'12345','parameter2':'23456'}
r = requests.post(url_comm,data=data)
print(r.content)
print(r.status_code)


#用Requests模拟post请求(application/json)
url_json = 'http://www.example/post'
json = json.dumps({'key1': 'value1', 'key2': 'value2'})
r = requests.post(url_json, data=json)
print (r.text)


#用Requests模拟post请求(text/xml)
xml = """my xml"""
headers = {'Content-Type': 'application/xml'}
requests.post(url_comm, data=xml, headers=headers)


#用Requests模拟post请求(multipart/form-data :上传文件用的表单)
files = {'file': open('C://Users//lx//Desktop//count.png', 'rb')}
r = requests.post(url_comm, files=files)
print(r.text)





